package com.primary.controller.check.checklogic;

import com.primary.controller.check.NameAndPasswordCheck;
import com.primary.controller.check.PhoneAndEmailCheck;
import com.primary.entity.Users;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Shen Jianhui
 * @time 2023/08/06 13:55 Sunday
 * @description To check the users' information which is passed by userDto
 */
public class UsersCheckLogic {

    /**
     * @author Shen Jianhui
     * @date 2023/08/06 Sunday
     * @param users
     * @description Some information in this params cannot be wrong or blank. It is necessary to check them
     * @return Result of checking on users' information
     */
    public static boolean userDtoCheckLogic(Users users) {
        /**************** Information that in users cannot be null or blank. Start ******************/
        if ((null == users.getName()     || StringUtils.isBlank(users.getName()))     ||
            (null == users.getPassword() || StringUtils.isBlank(users.getPassword())) ||
            (null == users.getAddress()  || StringUtils.isBlank(users.getAddress()))  ||
            (null == users.getPhone()    || StringUtils.isBlank(users.getPhone()))    ||
            (null == users.getEmail()    || StringUtils.isBlank(users.getEmail()))) {
          return false;
        }
        /**************** Information that in users cannot be null or blank. End ******************/
        /**************** Information that in users cannot be wrong. Start ******************/
        return (NameAndPasswordCheck.checkUserName(users.getName())) &&
                (NameAndPasswordCheck.checkPassword(users.getPassword())) &&
                (PhoneAndEmailCheck.isPhone(users.getPhone())) &&
                (PhoneAndEmailCheck.isEmail(users.getEmail()));
        /**************** Information that in users cannot be wrong. End ******************/
    }
}
